package shuashuami.hb.com.view;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import shuashuami.hb.com.hbclient.R;
import shuashuami.hb.com.hdlibrary.util.ToastUtil;

/**
 * Created by Administrator on 2017/6/20.
 */

public class OnlineConsultingDialog extends Dialog {

    private String qq, phone;

    private Context context;

    public OnlineConsultingDialog(Context context) {
        super(context, R.style.Dialog);
        this.context = context;
        setCustomDialog();
    }

    public OnlineConsultingDialog(Context context, String qq, String phone) {
        super(context, R.style.Dialog);
        this.context = context;
        this.qq = qq;
        this.phone = phone;
        setCustomDialog();
    }

    private void setCustomDialog() {
        View mView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_oneline_consulting_layout, null);
        LinearLayout llQQ = (LinearLayout) mView.findViewById(R.id.ll_add_qq);
        LinearLayout llPhone = (LinearLayout) mView.findViewById(R.id.ll_call_phone);
        llPhone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                call(context);
            }
        });
        llQQ.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                toQQ(qq);
            }
        });
        super.setContentView(mView);
    }

    @Override
    public void setContentView(int layoutResID) {
    }

    /**
     * 调用拨号界面
     */
    private void call(Context context) {
        Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phone));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    private void toQQ(String qq) {
        try {
            //第二种方式：可以跳转到添加好友，如果qq号是好友了，直接聊天
            String url = "mqqwpa://im/chat?chat_type=wpa&uin=" + qq;//uin是发送过去的qq号码
            context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
        } catch (Exception e) {
            e.printStackTrace();
            ToastUtil.showShort(context, "请检查是否安装QQ");
        }
    }

    @Override
    public void setContentView(View view, ViewGroup.LayoutParams params) {
    }

    @Override
    public void setContentView(View view) {
    }
}
